/**
 * Created by chaoCheng on 2017/1/13.
 */
function DetailController(
    fileandgroups,//路由中预加载数据的注入
    Stream,
    Sorter,
    Detail,
    $uibModal,
    $log,
    $scope,
    $state,
    $stateParams
) {
    var vm=this
    fileandgroups.$promise.then(function (response) {
        console.info(response);
        vm.planfiles = response.planFiles
        vm.plangroups = response.plangroups
        vm.planName = response.planName
    })
    vm.deletefile = function(planfile) {
        // 模拟窗口打开之后执行该函数
        var modalInstance = $uibModal.open({
            animation: $scope.animationsEnabled,
            templateUrl: 'deletePlanFileContent.html',
            controller: 'PlanFileInstanceCtrl',
            size: planfile
        });
        // 模拟窗口关闭后回传调用
        modalInstance.result.then(function (selectedItem) {
            if(selectedItem == 'ok') {
                Detail.deleteFile({
                    id : planfile.id
                }).$promise.then(function(){
                    $state.reload($state.current)
                })
            }
        });
    }
    vm.deletegroup = function(plangroup) {
        // 模拟窗口打开之后执行该函数
        console.info(plangroup);
        var modalInstance = $uibModal.open({
            animation: $scope.animationsEnabled,
            templateUrl: 'deleteGroupContent.html',
            controller: 'GroupInstanceCtrl',
            size: plangroup
        });
        // 模拟窗口关闭后回传调用
        modalInstance.result.then(function (selectedItem) {
            if(selectedItem == 'ok') {
                Detail.deleteGroup({
                    id : plangroup.id
                }).$promise.then(function(){
                    $state.reload($state.current)
                })
            }
        });
    }
    vm.filepreview = function(planfile) {
        // $state.go('filepreview' , {'planId':$stateParams.planId,'filePath':planfile.filePath})
        var url = $state.href('filepreview',{'planId':$stateParams.planId,'filePath':planfile.filePath});
        window.open(url,'_blank');
    }
    vm.addgroup = function() {
        $state.go('groupSearch' , {'planId':$stateParams.planId})
    }
    vm.addfile = function() {
        $state.go('fileAdd' ,{'planId':$stateParams.planId})
    }

}
